﻿using System;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Babushka
{
    class Camera
    {
        private float _zoom;
        private Matrix _transform;
        private Vector2 _position;
        private float _rotation;

        public Camera()
        {
            _zoom = 1;
            _rotation = 0;
            this._position = Vector2.Zero;
        }

        public float Rotation
        {
            get
            {
                return this._rotation;
            }
            set
            {
                this._rotation = value;
            }
        }
        public Vector2 Position
        {
            get
            {
                return this._position;
            }
            set
            {
                this._position = value;
            }
        }
        public float Zoom
        {
            get
            {
                return this._zoom;
            }
            set
            {
                this._zoom = value;
                if (_zoom < 0.1f)
                    _zoom = 0.1f;
            }
        }

        public Matrix GetTransformation(GraphicsDevice graphicsDevice)
        {
            _transform =       // Thanks to o KB o for this solution
              Matrix.CreateTranslation(new Vector3(-Position.X, -Position.Y, 0)) *
                                         Matrix.CreateRotationZ(Rotation) *
                                         Matrix.CreateScale(new Vector3(Zoom, Zoom, 1));
            return _transform;
        }
    }
}
